//
//  BIDMemberWithCheckboxCell.m
//  HomeworkAssistant
//
//  Created by mal on 15/11/17.
//  Copyright © 2015年 mal. All rights reserved.
//

#import "BIDMemberCell.h"

@interface BIDMemberCell()
{
    NSString *_imgNameForChoose;
    NSString *_imgNameForInchoose;
}
@end

@implementation BIDMemberCell
@synthesize btn;
@synthesize delegate;
@synthesize indexPath;
@synthesize imgView;
@synthesize checkBoxImgView;
@synthesize nameLabel;
@synthesize stepLevel;
@synthesize stepWidth;
@synthesize isPerson;
@synthesize chooseType;
@synthesize chooseStatus;
@synthesize isChoose;

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
    isChoose = NO;
    if(chooseType == TYPE_RADIO)
    {
        _imgNameForChoose = @"radio_choose.png";
        _imgNameForInchoose = @"radio_inchoose.png";
        [imgView setImage:[UIImage imageNamed:_imgNameForInchoose]];
    }
    else if(chooseType == TYPE_CHECK)
    {
        _imgNameForChoose = @"check_choose.png";
        _imgNameForInchoose = @"check_inchoose.png";
        [imgView setImage:[UIImage imageNamed:_imgNameForInchoose]];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
    
//
- (void)setStepLevel:(NSUInteger)stepLevel1
{
    stepLevel = stepLevel1;
    _leftForImgViewConstraint.constant = 16+stepLevel*stepWidth;
}

- (void)setStepWidth:(NSUInteger)stepWidth1
{
    stepWidth = stepWidth1;
}

- (void)setIsPerson:(BOOL)isPerson1
{
    isPerson = isPerson1;
    _widthForImgViewConstraint.constant = isPerson1 ? 0 : 18;
}

- (void)setChooseType:(CHOOSE_TYPE)chooseType1
{
    chooseType = chooseType1;
    if(chooseType == TYPE_RADIO)
    {
        _imgNameForChoose = @"radio_choose.png";
        _imgNameForInchoose = @"radio_inchoose.png";
        [checkBoxImgView setImage:[UIImage imageNamed:_imgNameForInchoose]];
    }
    else if(chooseType == TYPE_CHECK)
    {
        _imgNameForChoose = @"check_choose.png";
        _imgNameForInchoose = @"check_inchoose.png";
        [checkBoxImgView setImage:[UIImage imageNamed:_imgNameForInchoose]];
    }
}
/**
 *  选中
 */
- (void)choose
{
    isChoose = YES;
    [checkBoxImgView setImage:[UIImage imageNamed:_imgNameForChoose]];
}
/**
 *  未选中
 */
- (void)inChoose
{
    isChoose = NO;
    [checkBoxImgView setImage:[UIImage imageNamed:_imgNameForInchoose]];
}

- (void)showDisclosureIndicator
{
    checkBoxImgView.hidden = YES;
    btn.hidden = YES;
    self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

- (void)setIsChoose:(BOOL)isChoose1
{
    isChoose = isChoose1;
    NSString *strImgName = isChoose ? _imgNameForChoose : _imgNameForInchoose;
    [checkBoxImgView setImage:[UIImage imageNamed:strImgName]];
}

- (void)setChooseStatus:(CHOOSE_STATUS)chooseStatus1
{
    chooseStatus = chooseStatus1;
    switch(chooseStatus)
    {
        case CHOOSE_STATUS_CHOOSE:
        {
            [checkBoxImgView setImage:[UIImage imageNamed:_imgNameForChoose]];
        }
            break;
        case CHOOSE_STATUS_INCHOOSE:
        {
            [checkBoxImgView setImage:[UIImage imageNamed:_imgNameForInchoose]];
        }
            break;
        case CHOOSE_STATUS_PART:
        {
            [checkBoxImgView setImage:[UIImage imageNamed:@"check_partChoose.png"]];
        }
            break;
    }
}

- (IBAction)btnDownHandler:(id)sender
{
    if(chooseType == TYPE_CHECK)
    {
        if(chooseStatus == CHOOSE_STATUS_CHOOSE)
        {
            isChoose = NO;
            chooseStatus = CHOOSE_STATUS_INCHOOSE;
            [checkBoxImgView setImage:[UIImage imageNamed:_imgNameForInchoose]];
        }
        else
        {
            isChoose = YES;
            chooseStatus = CHOOSE_STATUS_CHOOSE;
            [checkBoxImgView setImage:[UIImage imageNamed:_imgNameForChoose]];
        }
        [delegate selectAtIndexPath:indexPath selected:isChoose];
    }
    else if(chooseType == TYPE_RADIO)
    {
        if(!isChoose)
        {
            isChoose = YES;
            [checkBoxImgView setImage:[UIImage imageNamed:_imgNameForChoose]];
            [delegate selectAtIndexPath:indexPath selected:isChoose];
        }
        else
        {}
    }
}

@end
